package com.ghck.server.dao;
import java.util.List;

import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.InsertProvider;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.SelectProvider;
import org.apache.ibatis.annotations.UpdateProvider;

import com.ghck.server.dao.provider.PatientEventProvider;
import com.ghck.server.model.PatientEvent;
import com.ghck.server.model.query.PatientEventQuery;
/**
 * 用户健康数据  <br>
 * t_patient_event <br>
 * v1.0 2016-05-01
 */
 public interface PatientEventMapper {
 	
 	/**
 	*根据id删除 用户健康数据
 	*/
 	@Delete("delete from t_patient_event where id=#{id}")
 	public Integer deleteById(Integer id);
 	
 	/**
 	* 批量新增 用户健康数据
 	*/
 	@InsertProvider(method="batchInsert",type=PatientEventProvider.class)
	@Options(useGeneratedKeys=true,keyColumn="id",keyProperty="list[0].id")
 	public Integer batchInsert(List<? extends PatientEvent> patientEvents);
 	
 	/**
 	* 新增 用户健康数据
 	*/
 	@InsertProvider(method="insert",type=PatientEventProvider.class)
	@Options(useGeneratedKeys=true)
 	public Integer insert(PatientEvent domain);
 
 	
 	/**
 	*更新 用户健康数据
 	*/
 	@UpdateProvider(method="update",type=PatientEventProvider.class)
 	public Integer update(PatientEvent domain);
 	
 	/**
 	*根据ID查询 用户健康数据
 	*/
	@Select("select * from t_patient_event where id=#{id}")
	public PatientEvent findById(Integer id);
	
	@Select("select * from t_patient_event where uuid=#{uuid}")
	public PatientEvent findByUuid(String uuid);
	
	@Select("select * from t_patient_event where uuid=#{uuid} and user_id=#{userId}")
	public PatientEvent findByUuidAndUserId(@Param("uuid") String uuid,@Param("userId") Integer userId);
	
	
	/**
 	*通过query 查询 用户健康数据
 	*/
 	@SelectProvider(method="findByQuery",type=PatientEventProvider.class)
 	public List<PatientEvent> findByQuery(PatientEventQuery query);
 	
 	/**
 	*通过query count总条数
 	*/
 	@SelectProvider(method="countByQuery",type=PatientEventProvider.class)
 	public Integer countByQuery(PatientEventQuery query);
 	
 	/**
 	* 通过ids查询
 	*/
 	@SelectProvider(method="findByIds",type=PatientEventProvider.class)
 	public List<PatientEvent> findByIds(List<Integer> ids);
 	
 	@Select("select * from t_patient_event where user_id=#{userId} and category_id=#{categoryId} order by id desc limit 1")
 	public PatientEvent findLastByUserIdCategoryId(@Param("categoryId") Integer categoryId,@Param("userId") Integer userId);
 	

}	